import { McpClient } from "@modelcontextprotocol/sdk/client/mcp.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

async function main() {
    // 创建MCP客户端
    const client = new McpClient();
    
    // 创建stdio传输
    const transport = new StdioClientTransport();
    
    // 连接到MCP服务器
    await client.connect(transport);
    
    console.log('已连接到MCP服务器');

    try {
        // 调用drawStar工具
        console.log('调用drawStar工具...');
        const drawStarResult = await client.callTool('drawStar', {
            center: [39.9042, 116.4074], // 北京坐标
            radius: 1000
        });
        console.log('drawStar结果:', drawStarResult);

        // 等待1秒
        await new Promise(resolve => setTimeout(resolve, 1000));

        // 调用zoomToStar工具
        console.log('调用zoomToStar工具...');
        const zoomToStarResult = await client.callTool('zoomToStar', {
            center: [39.9042, 116.4074],
            radius: 1000
        });
        console.log('zoomToStar结果:', zoomToStarResult);

    } catch (error) {
        console.error('调用工具时出错:', error);
    }

    // 关闭连接
    await client.disconnect();
    console.log('已断开MCP连接');
}

main().catch(console.error); 